/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "PlayerHandler.h"
#include "../../tools/PacketReader.h"
#include "../../tools/PacketCreator.h"
#include "../../server/Channels.h"
#include "../../server/Channel.h"
#include "../../server/Player.h"
#include "../../server/Players.h"
#include "../../net/world/World.h"

void PlayerHandler::reportHandle(PacketReader &packet) {
	packet.read();
	string victim = packet.readString();
	packet.read();
	string description = packet.readString();
	if(player->getPossibleReports() == 0) {
		player->send(PacketCreator().showMessage("You do not have any reports left.", 5));
		return;
	}
	player->decreaseReports();
	player->send(PacketCreator().reportResponse(player->getPossibleReports()));
	Channels *chans = player->getWorld()->getChannels();
	int chanCount = chans->getChannelsCount();
	for(int i = 0; i < chanCount; i++) {
		hash_map <int,Player*> *chanPlayers = chans->getChannel(i)->getPlayers()->getPlayers();
		hash_map <int,Player*>::iterator it;
		for(it = chanPlayers->begin(); it != chanPlayers->end(); it++) {
			if(it->second->isGM())
				it->second->send(PacketCreator().showMessage(victim + " was reported for: " + description + " by: " + player->getName(), 6));
		}
	}
}